package com.example.myapplication.HomeActivity.HomeGVShop;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.myapplication.HomeBean.HomeGvShopBean;
import com.example.myapplication.HomeGVShopHuoPaoFragment.GaoShePaoFragment;
import com.example.myapplication.HomeGVShopHuoPaoFragment.JianPaoFragment;
import com.example.myapplication.HomeGVShopHuoPaoFragment.LiuDanPaoFragment;
import com.example.myapplication.HomeGVShopHuoPaoFragment.HuoJianPaoFragment;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class HomeGVHuoPao extends AppCompatActivity {
    List<HomeGvShopBean>list=new ArrayList<>();
    RadioGroup HomeGV_Shop_HuoPao_RG;
    RadioButton HomeGV_Shop_HuoPao_rb1,HomeGV_Shop_HuoPao_rb2,HomeGV_Shop_HuoPao_rb3,HomeGV_Shop_HuoPao_rb4;
    FragmentManager fragmentManager;
    FragmentTransaction fragmentTransaction;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_gv_huopao);
        fragmentManager=getSupportFragmentManager();
        fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.HomeShop_HuoPao_fl,new GaoShePaoFragment());
        fragmentTransaction.commit();
        initView();
        HomeGV_Shop_HuoPao_rb1.setBackgroundColor(getResources().getColor(R.color.HomeShop_tap));

    }

    private void initView() {
        HomeGV_Shop_HuoPao_RG=findViewById(R.id.HomeShop_HuoPao_RG);
        HomeGV_Shop_HuoPao_rb1=findViewById(R.id.HomeShop_HuoPao_rb1);
        HomeGV_Shop_HuoPao_rb2=findViewById(R.id.HomeShop_HuoPao_rb2);
        HomeGV_Shop_HuoPao_rb3=findViewById(R.id.HomeShop_HuoPao_rb3);
        HomeGV_Shop_HuoPao_rb4=findViewById(R.id.HomeShop_HuoPao_rb4);
        HomeGV_Shop_HuoPao_RG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                fragmentTransaction=fragmentManager.beginTransaction();
                NoSelect();
                switch (i){
                    case R.id.HomeShop_HuoPao_rb1:
                        fragmentTransaction.replace(R.id.HomeShop_HuoPao_fl,new GaoShePaoFragment());
                        HomeGV_Shop_HuoPao_rb1.setBackgroundColor(getResources().getColor(R.color.HomeShop_tap));
                        break;
                    case R.id.HomeShop_HuoPao_rb2:
                        fragmentTransaction.replace(R.id.HomeShop_HuoPao_fl,new JianPaoFragment());
                        HomeGV_Shop_HuoPao_rb2.setBackgroundColor(getResources().getColor(R.color.HomeShop_tap));
                        break;
                    case R.id.HomeShop_HuoPao_rb3:
                        fragmentTransaction.replace(R.id.HomeShop_HuoPao_fl,new LiuDanPaoFragment());
                        HomeGV_Shop_HuoPao_rb3.setBackgroundColor(getResources().getColor(R.color.HomeShop_tap));
                        break;
                    case R.id.HomeShop_HuoPao_rb4:
                        fragmentTransaction.replace(R.id.HomeShop_HuoPao_fl,new HuoJianPaoFragment());
                        HomeGV_Shop_HuoPao_rb4.setBackgroundColor(getResources().getColor(R.color.HomeShop_tap));
                        break;
                }
            }
        });
    }

    private void NoSelect() {
        HomeGV_Shop_HuoPao_rb1.setBackgroundColor(getResources().getColor(R.color.white));
        HomeGV_Shop_HuoPao_rb2.setBackgroundColor(getResources().getColor(R.color.white));
        HomeGV_Shop_HuoPao_rb3.setBackgroundColor(getResources().getColor(R.color.white));
        HomeGV_Shop_HuoPao_rb4.setBackgroundColor(getResources().getColor(R.color.white));
    }
}